package Database;

import java.sql.*;
import java.util.ArrayList;

import Model.Role;

//import Database.DBConnection;

public class RoleDB
{

	public static ArrayList<Role> getRoleTemplate()
	{
		Connection con = DBConnection.connect(true);
		PreparedStatement stmt = null;
		ResultSet rs = null;
		String select = "SELECT * FROM Role ORDER BY Role_Name";

		ArrayList<Role> roleArr = new ArrayList<Role>();
		Role role = null;

		try
		{
			stmt = con.prepareStatement(select);
			// stmt.setString(1, credID);
			rs = stmt.executeQuery();
			while (rs.next())
			{
				role = new Role();
				role.setId(rs.getString("Role_ID"));
				role.setName(rs.getString("Role_Name"));

				roleArr.add(role);
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
			role = null;
		}
		finally
		{
			try
			{
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
				if (con != null)
					con.close();
			}
			catch (SQLException e)
			{
			}
		}

		return roleArr;
	}
}
